-
Notifications
You must be signed in to change notification settings - Fork 110
feat(l1): download all headers from new to old as first step of full sync #4812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Lines of code reportTotal lines added: Detailed view
|
…te::into_fullsync
fbfca51
to
119c5cf
Compare
/// Block headers downloaded during fullsync column family: [`u8;_`] => [`Vec<u8>`] | ||
/// - [`u8;_`] = `block_number.to_le_bytes()` | ||
/// - [`Vec<u8>`] = `BlockHeaderRLP::from(block.header.clone()).bytes().clone()` | ||
const CF_FULLSYNC_HEADERS: &str = "fullsync_headers"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be merged with the main headers table. I opened #4903 to check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
if !block_headers.is_empty() | ||
&& are_block_headers_chained(&block_headers, &order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a change in behavior from later versions we noticed. Before, empty responses were never forwarded to the user, but somewhere down the line it changed, producing errors that were previously unreachable.
let first_header = block_headers.first().ok_or(SyncError::NoBlocks)?; | ||
let last_header = block_headers.last().ok_or(SyncError::NoBlocks)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These errors are actually unreachable, since request_block_headers_from_hash
never returns an empty Vec
. I think we should change, in another PR, request_block_headers_from_hash
to return a plain Vec
instead of an Option<Vec<>>
, and interpret an empty Vec
the same as the current None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a nitpick comment, it can be checked in the future
// Stores current Snap State | ||
snap_state: SnapState, | ||
// Stores fetched headers during a fullsync | ||
fullsync_headers: HashMap<BlockNumber, BlockHeader>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is expected to have less than < 10000~ it might be better to use a btree too here
Motivation
In order to properly handle reorgs, we should download headers from the latest announced fcu head until me meet our local chain instead of requesting headers from our current head till we reach the fcu head, as our current head may not be part of the canonical chain after a reorg.
The main behaviour changes imposed by this are that
A) We must request all headers before we can begin to execute the blocks
B) We are no longer able to keep all headers in memory (in case of long syncs)
Description
BlockSyncState
&FullBlockSyncState
Observations & Follow-Up Work
The current implementation downloads all headers first before processing blocks without any sort of checkpoint system to keep progress in case of unexpected failures or shutdowns. When comparing to other implementations this doesn't seem to be much of an issue as header download phase is pretty quick. Having all headers downloaded as a first step can also allow us to download headers non-sequentially (aka divide the chain into batches and fetch them in parallel). Note that this is not as high priority as it would only affect large full syncs, but it may slow down our efforts when using full sync to test vm behaviour. Potential follow up work:
SnapBlockSyncState
struct can be improved/removedCloses #4717 + Closes #4776